﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media.Animation;

namespace HuiZe.education.View
{
    /// <summary>
    /// PopupView.xaml 的交互逻辑
    /// </summary>
    public partial class PopupView : Window
    {
        DoubleAnimation closeAnimation;
        private bool IsClosed = false;
        public PopupView()
        {
            InitializeComponent();
            IsVisibleChanged += PopupView_IsVisibleChanged;
            closeAnimation = new DoubleAnimation()
            {
                From = 1,
                To = 0,
                Duration = new TimeSpan(0, 0, 0, 0, 300)
            };
        }


        protected override void OnClosing(CancelEventArgs e)
        {

        }

        public  void DoubleAnimationClose()
        {
            if (!IsClosed)
            {
                closeAnimation.Completed += delegate
                {
                    IsClosed = true;
                    this.Close();
                };
                this.BeginAnimation(OpacityProperty, closeAnimation);
            }
        }

        private void PopupView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                this.BeginAnimation(OpacityProperty, (DoubleAnimation)FindResource("doubleAnimation"));
            }
        }
    }
}
